package com.ruoyi.web.controller.customer;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.repairs.domain.CrmRepairs;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.suggest.domain.CrmSuggest;
import com.ruoyi.suggest.service.ICrmSuggestService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 维修Controller
 * 
 * @author hct
 * @date 2022-02-11
 */
@RestController
@RequestMapping("/suggest/suggest")
public class CrmSuggestController extends BaseController
{
    @Autowired
    private ICrmSuggestService crmSuggestService;

    /**
     * 查询维修列表
     */
    @PreAuthorize("@ss.hasPermi('suggest:suggest:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmSuggest crmSuggest)
    {
        startPage();
        List<CrmSuggest> list = crmSuggestService.selectCrmSuggestList(crmSuggest);
        return getDataTable(list);
    }

    /**
     * 导出维修列表
     */
    @PreAuthorize("@ss.hasPermi('suggest:suggest:export')")
    @Log(title = "维修", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CrmSuggest crmSuggest)
    {
        List<CrmSuggest> list = crmSuggestService.selectCrmSuggestList(crmSuggest);
        ExcelUtil<CrmSuggest> util = new ExcelUtil<CrmSuggest>(CrmSuggest.class);
        util.exportExcel(response, list, "维修数据");
    }

    /**
     * 获取维修详细信息
     */
    @PreAuthorize("@ss.hasPermi('suggest:suggest:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(crmSuggestService.selectCrmSuggestById(id));
    }

    /**
     * 新增维修
     */
    @PreAuthorize("@ss.hasPermi('suggest:suggest:add')")
    @Log(title = "维修", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmSuggest crmSuggest)
    {
        return toAjax(crmSuggestService.insertCrmSuggest(crmSuggest));
    }

    /**
     * 修改维修
     */
    @PreAuthorize("@ss.hasPermi('suggest:suggest:edit')")
    @Log(title = "维修", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmSuggest crmSuggest)
    {
        return toAjax(crmSuggestService.updateCrmSuggest(crmSuggest));
    }

    /**
     * 修改维修
     */
    @PreAuthorize("@ss.hasPermi('suggest:suggest:review')")
    @Log(title = "维修", businessType = BusinessType.UPDATE)
    @PostMapping("/review")
    public AjaxResult review(@RequestBody CrmSuggest crmSuggest)
    {
        CrmSuggest crmSuggestN=new CrmSuggest();
        crmSuggestN.setId(crmSuggest.getId());
        crmSuggestN.setSuggestStatus(1);
        crmSuggestN.setSuggestStatus(1);
        crmSuggestN.setUserId(crmSuggest.getUserId());
        return toAjax(crmSuggestService.updateCrmSuggest(crmSuggestN));
    }

    /**
     * 修改维修
     */
    @PreAuthorize("@ss.hasPermi('repairs:repairs:review')")
    @Log(title = "维修", businessType = BusinessType.UPDATE)
    @PostMapping("/finish")
    public AjaxResult finish(@RequestBody CrmSuggest crmSuggest)
    {
        CrmSuggest crmSuggestN=new CrmSuggest();
        crmSuggestN.setId(crmSuggest.getId());
        crmSuggestN.setSuggestStatus(2);
        return toAjax(crmSuggestService.updateCrmSuggest(crmSuggestN));
    }


    /**
     * 删除维修
     */
    @PreAuthorize("@ss.hasPermi('suggest:suggest:remove')")
    @Log(title = "维修", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(crmSuggestService.deleteCrmSuggestByIds(ids));
    }
}
